home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / power / power.pro
Text File  |  1986-10-09  |  2KB  |  70 lines

  1. /*****
  2.    This program illustrates number crunching ability 
  3.    and predicate return versatility by calculating 
  4.    various elements needed in exponentiaiton
  5.    Eddy C. Vasile   5/8/86
  6.    PLC 213-689-5647
  7.    73317,701 on CompuServe
  8.    occ4edi@uclamvs on BitNet
  9. *****/   
  10.  
  11. predicates
  12.      power(real,real,real)
  13.      example1
  14.      example2
  15.      example3
  16.      run
  17. goal run.     
  18. clauses
  19. /***** 
  20.       Prolog tries hard to give you what you ask for. If the variables
  21.       Base and Exponent are bound (i.e. values assigned) then Result
  22.       is calculated, if Base and Result are Bound and Exponent is free
  23.       then a solution is returned for Exponent
  24. *****/    
  25.     
  26.      power(A,B,C):-
  27.           bound(A),
  28.           bound(B),
  29.           C=exp(B*ln(A)).
  30.      power(A,B,C):-
  31.           bound(A),
  32.           bound(C),
  33.           B=ln(C)/ln(A).
  34.      power(A,B,C):-
  35.           bound(B),
  36.           bound(C),
  37.           A=exp(ln(C)/B).
  38.           
  39.      run:-
  40.          example1,
  41.          example2,
  42.          example3.
  43.          
  44.      example1:-                  
  45.          makewindow(1,31,3,"Calculate Result",1,1,6,78),
  46.          write("Enter base >"),
  47.          readreal(A),
  48.          write("Enter Coefficient > "),
  49.          readreal(B),
  50.          power(A,B,C),
  51.          writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
  52.  
  53.      example2:-                  
  54.          makewindow(2,31,3,"Calculate Coefficient",7,1,6,78),
  55.          write("Enter base >"),
  56.          readreal(A),
  57.          write("Enter Result > "),
  58.          readreal(C),
  59.          power(A,B,C),
  60.          writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
  61.  
  62.      example3:-                  
  63.          makewindow(3,31,3,"Calculate Base",13,1,6,78),
  64.          write("Enter Coefficient >"),
  65.          readreal(B),
  66.          write("Enter Result > "),
  67.          readreal(C),
  68.          power(A,B,C),
  69.          writef("%1.3f ^ %-1.3f = %-1.3f\n",A,B,C).
  70.